package com.hou.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hou.mapper.UserBasicMapper;
import com.hou.parma.PageParam;
import com.hou.pojo.UserBasic;
import com.hou.service.IUserBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jack
 * @since 2022-03-26
 */
@Service
public class UserBasicServiceImpl extends ServiceImpl<UserBasicMapper, UserBasic> implements IUserBasicService {
    @Autowired
    UserBasicMapper userBasicMapper;


    @Override
    public List selectLists(PageParam pageParam) {//页数，大小
        List<UserBasic> records = userBasicMapper.selectPage(new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()), null).getRecords();

        return records;
    }

    @Override
    public Long selectCount() {
        Long aLong = userBasicMapper.selectCount(new QueryWrapper<UserBasic>());
        return aLong;
    }

    @Override
    public Long selectCount2(String name) {
        Long aLong = userBasicMapper.selectCount(new QueryWrapper<UserBasic>().like("UserName",name));
        return aLong;
    }

    @Override
    public int save1(UserBasic userBasic) {
        /*SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String 'format' = f.format(date);*/
        userBasic.setRegisterDate(new Date());
        int insert = userBasicMapper.insert(userBasic);
        return insert;
    }

    @Override
    public List search(PageParam pageParam) {
        List<UserBasic> search = userBasicMapper.selectPage(new Page<>(pageParam.getCurrentPage(),pageParam.getPageSize()),new QueryWrapper<UserBasic>().like("username",pageParam.getSearch())).getRecords();
        return search;
    }

    @Override
    public UserBasic selectid(Long id) {
//        UserBasic selectid = userBasicMapper.selectid(id);
        UserBasic selectid = userBasicMapper.selectById(id);
        return selectid;
    }


}
